/**
 * 音频资源配置
 * 定义游戏中所有音效和背景音乐的配置信息
 */

/**
 * 音效类型枚举
 * 定义游戏中所有可用的音效类型
 */
export enum SoundEffectType {
  JUMP = 'jump',
  SLIDE = 'slide',
  COLLECT_COIN = 'collectCoin',
  COLLECT_POWERUP = 'collectPowerUp',
  COLLISION = 'collision',
  GAME_OVER = 'gameOver',
  LEVEL_UP = 'levelUp',
  BUTTON_CLICK = 'buttonClick',
  POWERUP_ACTIVATE = 'powerUpActivate',
  POWERUP_EXPIRE = 'powerUpExpire',
  SHIELD_HIT = 'shieldHit',
  MAGNET_COLLECT = 'magnetCollect'
}

/**
 * 背景音乐类型枚举
 * 定义游戏中所有可用的背景音乐类型
 */
export enum BackgroundMusicType {
  MENU = 'menu',
  GAME_NORMAL = 'gameNormal',
  GAME_FAST = 'gameFast',
  BOSS_BATTLE = 'bossBattle',
  VICTORY = 'victory',
  GAME_OVER = 'gameOver'
}

/**
 * 音频资源配置接口
 * 定义音频资源的基本信息
 */
export interface AudioAssetConfig {
  /** 音频文件路径 */
  url: string;
  /** 默认音量 (0-1) */
  volume: number;
  /** 是否循环播放 */
  loop?: boolean;
  /** 音频描述 */
  description: string;
}

/**
 * 音效资源配置
 * 包含游戏中所有音效的配置信息
 */
export const SOUND_EFFECTS: Record<SoundEffectType, AudioAssetConfig> = {
  [SoundEffectType.JUMP]: {
    url: '/sounds/jump.mp3',
    volume: 0.7,
    description: '角色跳跃音效'
  },
  [SoundEffectType.SLIDE]: {
    url: '/sounds/slide.mp3',
    volume: 0.6,
    description: '角色滑铲音效'
  },
  [SoundEffectType.COLLECT_COIN]: {
    url: '/sounds/collect-coin.mp3',
    volume: 0.5,
    description: '收集金币音效'
  },
  [SoundEffectType.COLLECT_POWERUP]: {
    url: '/sounds/collect-powerup.mp3',
    volume: 0.8,
    description: '收集道具音效'
  },
  [SoundEffectType.COLLISION]: {
    url: '/sounds/collision.mp3',
    volume: 0.9,
    description: '碰撞音效'
  },
  [SoundEffectType.GAME_OVER]: {
    url: '/sounds/game-over.mp3',
    volume: 0.8,
    description: '游戏结束音效'
  },
  [SoundEffectType.LEVEL_UP]: {
    url: '/sounds/level-up.mp3',
    volume: 0.7,
    description: '升级音效'
  },
  [SoundEffectType.BUTTON_CLICK]: {
    url: '/sounds/button-click.mp3',
    volume: 0.4,
    description: '按钮点击音效'
  },
  [SoundEffectType.POWERUP_ACTIVATE]: {
    url: '/sounds/powerup-activate.mp3',
    volume: 0.6,
    description: '道具激活音效'
  },
  [SoundEffectType.POWERUP_EXPIRE]: {
    url: '/sounds/powerup-expire.mp3',
    volume: 0.5,
    description: '道具失效音效'
  },
  [SoundEffectType.SHIELD_HIT]: {
    url: '/sounds/shield-hit.mp3',
    volume: 0.7,
    description: '护盾被击中音效'
  },
  [SoundEffectType.MAGNET_COLLECT]: {
    url: '/sounds/magnet-collect.mp3',
    volume: 0.4,
    description: '磁铁收集音效'
  }
};

/**
 * 背景音乐资源配置
 * 包含游戏中所有背景音乐的配置信息
 */
export const BACKGROUND_MUSIC: Record<BackgroundMusicType, AudioAssetConfig> = {
  [BackgroundMusicType.MENU]: {
    url: '/music/menu.mp3',
    volume: 0.6,
    loop: true,
    description: '主菜单背景音乐'
  },
  [BackgroundMusicType.GAME_NORMAL]: {
    url: '/music/game-normal.mp3',
    volume: 0.5,
    loop: true,
    description: '普通游戏背景音乐'
  },
  [BackgroundMusicType.GAME_FAST]: {
    url: '/music/game-fast.mp3',
    volume: 0.6,
    loop: true,
    description: '快节奏游戏背景音乐'
  },
  [BackgroundMusicType.BOSS_BATTLE]: {
    url: '/music/boss-battle.mp3',
    volume: 0.7,
    loop: true,
    description: 'Boss战背景音乐'
  },
  [BackgroundMusicType.VICTORY]: {
    url: '/music/victory.mp3',
    volume: 0.8,
    loop: false,
    description: '胜利音乐'
  },
  [BackgroundMusicType.GAME_OVER]: {
    url: '/music/game-over.mp3',
    volume: 0.7,
    loop: false,
    description: '游戏结束音乐'
  }
};

/**
 * 音频主题配置接口
 * 定义不同游戏主题下的音频配置
 */
export interface AudioThemeConfig {
  /** 主题名称 */
  name: string;
  /** 背景音乐类型 */
  backgroundMusic: BackgroundMusicType;
  /** 主题特有的音效覆盖配置 */
  soundOverrides?: Partial<Record<SoundEffectType, Partial<AudioAssetConfig>>>;
}

/**
 * 音频主题配置
 * 定义不同游戏状态下的音频主题
 */
export const AUDIO_THEMES: Record<string, AudioThemeConfig> = {
  menu: {
    name: '主菜单',
    backgroundMusic: BackgroundMusicType.MENU
  },
  gameNormal: {
    name: '普通游戏',
    backgroundMusic: BackgroundMusicType.GAME_NORMAL
  },
  gameFast: {
    name: '快节奏游戏',
    backgroundMusic: BackgroundMusicType.GAME_FAST,
    soundOverrides: {
      [SoundEffectType.JUMP]: { volume: 0.8 },
      [SoundEffectType.COLLECT_COIN]: { volume: 0.6 }
    }
  },
  bossBattle: {
    name: 'Boss战',
    backgroundMusic: BackgroundMusicType.BOSS_BATTLE,
    soundOverrides: {
      [SoundEffectType.COLLISION]: { volume: 1.0 },
      [SoundEffectType.POWERUP_ACTIVATE]: { volume: 0.8 }
    }
  }
};

/**
 * 获取音效配置
 * @param type - 音效类型
 * @param themeOverrides - 主题覆盖配置
 * @returns 音效配置
 */
export function getSoundEffectConfig(
  type: SoundEffectType,
  themeOverrides?: Partial<Record<SoundEffectType, Partial<AudioAssetConfig>>>
): AudioAssetConfig {
  const baseConfig = SOUND_EFFECTS[type];
  const override = themeOverrides?.[type];
  
  return {
    ...baseConfig,
    ...override
  };
}

/**
 * 获取背景音乐配置
 * @param type - 背景音乐类型
 * @returns 背景音乐配置
 */
export function getBackgroundMusicConfig(type: BackgroundMusicType): AudioAssetConfig {
  return BACKGROUND_MUSIC[type];
}

/**
 * 获取音频主题配置
 * @param themeName - 主题名称
 * @returns 音频主题配置
 */
export function getAudioThemeConfig(themeName: string): AudioThemeConfig | null {
  return AUDIO_THEMES[themeName] || null;
}